export const data2json = (data: { [x: string]: any; }) => {
    const ans = [];
    for (const item in data) {
        const json: any = {};
        const value = data[item];
        json['key'] = item.toUpperCase();
        ans.push(json);
        for (const key in value.values) {
            json['percents'] = key;
            if(value.values[key]) {
                json['value'] = Number(value.values[key].toFixed(2));
            } else {
                json['value'] = 0;
            }
        }
    }
    return ans;
};


export const envStatus = (text: number) => {
    let status = "";
    switch (text) {
        case 0:
            status = "未采集";
            break;
        case 1:
            status = "成功";
            break;
        default:
            status = "失败";
    }

    return status;
}

export const replaceObjectKey = (data: { [x: string]: any; }, item: string) => {
    const arr = [];
    for (let i in data) {
        const map:any = {};
        map["date"] = i.split("T")[0];
        map["scales"] = data[i];
        map["item"] = item;
        arr.push(map);
    }
    return arr
};